#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>

int
numcmp(const void *p1, const void *p2)
{
	const int a = *(const int *)p1, b = *(const int *)p2;
	if (a == b)
		return 0;
	else if (a < b)
		return -1;
	return 1;
}

int
main(int argc, char **argv)
{
	static int v[200000];
	int m, a, b;
	register int i, j;

	scanf("%d", &m);
	for (j = i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		--a, --b;
		v[j++] = a;
		v[j++] = b;
	}
	qsort(v, (size_t) m * 2, sizeof v[0], numcmp);

	for (j = i = 1; i < m * 2; i++) {
		if (v[i - 1] != v[i])
			j++;
	}
	printf("%d\n", j);
	for (j = i = 0; i + 1 < m * 2; i++) {
		if (v[i] != v[i + 1]) {
			printf("%d %d\n", v[i] + 1, i - j + 1);
			j = i + 1;
		}
	}
	printf("%d %d\n", v[i] + 1, i - j + 1);

	return 0;
}
